package com.vvip.tool.time;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.TimeZone;

public class TimeZoneTest {

    public static void main(String[] args) {

        long timestamp = 1647489600000L; // 2022-03-15 12:00:00  Asia/Shanghai
        String timeZoneName = "America/New_York";
        Instant instant = Instant.ofEpochMilli(timestamp);
        ZoneId zoneId = TimeZone.getTimeZone(timeZoneName).toZoneId();

        ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(instant, zoneId);
        System.out.println(zonedDateTime);

        ZonedDateTime zonedDateTime1 = ZonedDateTime.ofInstant(instant,
                TimeZone.getTimeZone("Asia/Shanghai").toZoneId());
        System.out.println(zonedDateTime1);

        ZonedDateTime zonedDateTime2 = ZonedDateTime.ofInstant(instant,
                TimeZone.getTimeZone("GMT-05:00").toZoneId());
        System.out.println(zonedDateTime2);
    }
}
